<?
include("common/header.html");
include("../_made/le.cfg.php");
include("common/page.php");
include("common/left.html");
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
if(!$_SESSION['memberID']){exit("<script>window.location='dlogin.html'</script>");}
$sid=$_SESSION['sid'];
$did=$_REQUEST["did"];
$prodname=$_REQUEST['prodname'];
$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:7;
$sec=$op=$tpl=$prod=array();
$sel="select dname from pft_member where id=".$did;
$GLOBALS['le']->query($sel);
$GLOBALS['le']->fetch_assoc();
$dname=$GLOBALS['le']->f("dname");
$sel="select tid,dprice from uu_priceset where (aid=0 or aid=".$_SESSION['sid'].") and pid=".$did." order by aid ASC";
$GLOBALS['le']->query($sel);
while($row=$GLOBALS['le']->fetch_assoc()){
	$op[$row['tid']]=$row['dprice'];
}
$sel="select pids from pft_product_sale_list where fid=".$did." and aid=".$sid;
$GLOBALS['le']->query($sel);
$GLOBALS['le']->fetch_assoc();
$can=$GLOBALS['le']->f("pids");
if($can!="A"){
	$can=explode(",",$can);
}
// $sel="select pid from pft_p_apply_evolute where sid=".$sid." and fid=".$did;
// $GLOBALS['le']->query($sel);
// while($row=$GLOBALS['le']->fetch_assoc()){
	// $sec[]=$row['pid'];
// }
$sel="select tplid from uu_fx_tpl_cs where fxid=".$did;
$GLOBALS['le']->query($sel);
$GLOBALS['le']->fetch_assoc();
$tplid=$GLOBALS['le']->f("tplid");
$sel = "select p.id,p.apply_did,p_name,e.lvl,e.sid from uu_products p left join pft_p_apply_evolute e on p.id=pid and fid=".$sid."  where p.p_status in (0,3) and p.apply_limit=1 and (p.apply_did=".$sid." or active=1) and p_name like '%$prodname%' order by p.id DESC ";//." limit ".($currentPage-1)*$pageSize.",".$pageSize

if($_GET['debug']){
	echo $sel;
}
$GLOBALS['le']->query($sel);
while($row=$GLOBALS['le']->fetch_assoc()){
    $pri=$s->get_Dynamic_Price_Merge($row['id'],date("Y-m-d"),1);
    if($pri==-1){
	$pri=$s->get_Dynamic_Price_Merge($row['id'],date("Y-m-d"),2);}
	if($pri==-1){continue;}
	else{$row['fp']=$pri/100;}
	if($row['apply_did']!=$sid){continue;}
	switch($row['lvl']){
		case 1:
			$lvl.="(tid=".$row['id']." and pid=".$_SESSION['sid']." and aid=0) or ";
			break;
		case 2:
			$lvl.="(tid=".$row['id']." and pid=".$_SESSION['sid']." and aid=".$row['sid'].") or (tid=".$row['id']." and pid=".$row['sid']." and aid=0) or ";
			break;
	}
	// if(($can=="A" && $row['apply_did']==$sid) || in_array($row['id'],$can) || in_array($row['id'],$sec)){
	if(($can=="A" && $row['apply_did']==$sid) || in_array($row['id'],$can)){
		$row['pri']=$op[$row['id']]/100;
		$row['disabled']="";
		$row['checked']="checked";
	}
	else{
		$row['pri']=$row['checked']="";
		$row['disabled']="disabled";
	}
	$prod[$row['id']]=$row;
}
// if($lvl){
	// $sel="select tid,dprice from uu_priceset where ".trim($lvl," or ");
	// $GLOBALS['le']->query($sel);
	// while($row=$GLOBALS['le']->fetch_assoc()){
		// $prod[$row['tid']]['fp']+=$row['dprice']/100;
	// }
// }
if($_GET['debug']){
	print_r($prod);
}
include("tpl/priceset.html");
include("common/footer.html");?>